package com.xbts.web.controller.cloud;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xbts.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnHelp;
import com.xbts.system.service.ICnHelpService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 帮助中心Controller
 * @author xbts
 * @date 2023-08-03
 */
@Api("帮助中心")
@RestController
@RequestMapping("/system/help")
public class CnHelpController extends BaseController {

    @Autowired
    private ICnHelpService cnHelpService;

    /**
     * 不包含最后一级查询帮助
     */
    @ApiOperation("查询帮助")
    @PreAuthorize("@ss.hasPermi('system:help:list')")
    @GetMapping("/manager/list")
    public AjaxResult selectHelpList(CnHelp cnHelp){
        return success(cnHelpService.selectHelpList(cnHelp));
    }

    /**
     * 包含最后一级  查询帮助
     */
    @ApiOperation("查询帮助")
//    @PreAuthorize("@ss.hasPermi('system:help:list')")
    @GetMapping("/list")
    public AjaxResult getHelpList(CnHelp cnHelp){
        return success(cnHelpService.selectCnHelp(cnHelp));
    }

    /**
     * 查询出没有子节点的数据列表
     * 查询帮助列表
     */
    @ApiOperation("查询帮助")
    @PreAuthorize("@ss.hasPermi('system:help:list')")
    @GetMapping("/list/{helpId}")
    public TableDataInfo selectCnHelpById(@PathVariable Long helpId, String helpName){
        startPage();
        List<CnHelp> cnHelps = cnHelpService.selectCnHelpById(helpId, helpName);
        return getDataTable(cnHelps);
    }

    /**
     * 新增帮助内容
     */
    @ApiOperation("新增帮助内容")
    @PreAuthorize("@ss.hasPermi('system:help:add')")
    @Log(title = "新增帮助内容", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult add(@Validated @RequestBody CnHelp cnHelp) {
        return toAjax(cnHelpService.insertCnHelp(cnHelp));
    }


    /**
     * 删除帮助内容
     */
    @ApiOperation("删除帮助内容")
    @PreAuthorize("@ss.hasPermi('system:help:remove')")
    @Log(title = "删除帮助内容", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult deleteContent(Long helpId) {
        return toAjax(cnHelpService.deleteContentById(helpId));
    }
    /**
     * 批量删除帮助内容
     */
    @ApiOperation("批量删除帮助内容")
    @PreAuthorize("@ss.hasPermi('system:help:remove')")
    @Log(title = "批量删除帮助内容", businessType = BusinessType.DELETE)
    @ApiImplicitParam(name = "ids", value = "帮助id集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PostMapping("/batchDelete")
    public AjaxResult batchDeleteContent(@RequestBody List<String> ids) {
        return toAjax(cnHelpService.batchDeleteContentById(ids));
    }

    /**
     * 更新帮助内容
     */
    @ApiOperation("更新帮助内容")
    @PreAuthorize("@ss.hasPermi('system:help:edit')")
    @Log(title = "更新帮助内容", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult updateContent(@RequestBody CnHelp cnHelp) {
        return toAjax(cnHelpService.updateHelp(cnHelp));
    }
}